package com.ctgu.server.mapper;

import com.ctgu.server.dao.entity.Form;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ctgu
 * @since 2023-05-17
 */
@Mapper
public interface FormMapper extends BaseMapper<Form> {

    //用户报名
    @Update("update form set user_count=user_count+1,version=version+1 where id =#{formId} and version=#{version}")
    void applyUserToForm(String formId,Integer version);

    //查询数表名表无限制的字段
    @Select("select id from form where scope like '无限制'")
    List<String> selectUserGroupForm();

    //查询表名为
    @Select("select id from form where scope like '无限制' union select form_id from form_group where group_id in  (select group_id from group_user where user_id=#{userId})")
    List<String> selectUserGroupAllForm(String userId);

    @Select("select * from form where id in (select id from form where scope like '无限制' union select form_id from form_group where group_id in  (select group_id from group_user where user_id=#{userId}))")
    List<Form> selectForms(String userId);

}
